home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / libs / dummylib.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  6KB  |  239 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dummylib.c,v 1.5 1996/09/13 17:57:09 digulla Exp $
  4.     $Log: dummylib.c,v $
  5.     Revision 1.5  1996/09/13 17:57:09  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.4  1996/09/12 14:52:04  digulla
  9.     Use correct way to access external names (was missing)
  10.  
  11.     Revision 1.3  1996/08/13 15:35:11  digulla
  12.     Replaced __AROS_LA by __AROS_LHA
  13.  
  14.     Revision 1.2  1996/08/01 17:41:28  digulla
  15.     Added standard header for all files
  16.  
  17.     Desc:
  18.     Lang:
  19. */
  20. #include <exec/types.h>
  21. #include <exec/resident.h>
  22. #include <clib/exec_protos.h>
  23. #include <aros/libcall.h>
  24. #ifdef __GNUC__
  25. #   include "dummylib_gcc.h"
  26. #endif
  27. #include "initstruct.h"
  28.  
  29. struct inittable;
  30. extern const char name[];
  31. extern const char version[];
  32. extern const APTR inittabl[4];
  33. extern void *const functable[];
  34. extern const struct inittable datatable;
  35. extern struct dummybase *__AROS_SLIB_ENTRY(init,dummy)();
  36. extern struct dummybase *__AROS_SLIB_ENTRY(open,dummy)();
  37. extern BPTR __AROS_SLIB_ENTRY(close,dummy)();
  38. extern BPTR __AROS_SLIB_ENTRY(expunge,dummy)();
  39. extern int __AROS_SLIB_ENTRY(null,dummy)();
  40. extern ULONG __AROS_SLIB_ENTRY(add,dummy)();
  41. extern ULONG __AROS_SLIB_ENTRY(asl,dummy)();
  42. extern const char end;
  43.  
  44. int entry(void)
  45. {
  46.     /* If the library was executed by accident return error code. */
  47.     return -1;
  48. }
  49.  
  50. const struct Resident resident=
  51. {
  52.     RTC_MATCHWORD,
  53.     (struct Resident *)&resident,
  54.     (APTR)&end,
  55.     RTF_AUTOINIT,
  56.     1,
  57.     NT_LIBRARY,
  58.     0,
  59.     (char *)name,
  60.     (char *)&version[6],
  61.     (ULONG *)inittabl
  62. };
  63.  
  64. const char name[]="dummy.library";
  65.  
  66. const char version[]="$VER: dummy 1.0 (28.3.96)\n\015";
  67.  
  68. const APTR inittabl[4]=
  69. {
  70.     (APTR)sizeof(struct dummybase),
  71.     (APTR)functable,
  72.     (APTR)&datatable,
  73.     &__AROS_SLIB_ENTRY(init,dummy)
  74. };
  75.  
  76. void *const functable[]=
  77. {
  78.     &__AROS_SLIB_ENTRY(open,dummy),
  79.     &__AROS_SLIB_ENTRY(close,dummy),
  80.     &__AROS_SLIB_ENTRY(expunge,dummy),
  81.     &__AROS_SLIB_ENTRY(null,dummy),
  82.     &__AROS_SLIB_ENTRY(add,dummy),
  83.     &__AROS_SLIB_ENTRY(asl,dummy),
  84.     (void *)-1
  85. };
  86.  
  87. struct inittable
  88. {
  89.     S_CPYO(1,1,B);
  90.     S_CPYO(2,1,L);
  91.     S_CPYO(3,1,B);
  92.     S_CPYO(4,1,W);
  93.     S_CPYO(5,1,W);
  94.     S_CPYO(6,1,L);
  95.     S_END (end);
  96. };
  97.  
  98. #define O(n) offsetof(struct dummybase,n)
  99.  
  100. const struct inittable datatable=
  101. {
  102.     { { I_CPYO(1,B,O(library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  103.     { { I_CPYO(1,L,O(library.lib_Node.ln_Name)), { (IPTR)name } } },
  104.     { { I_CPYO(1,B,O(library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  105.     { { I_CPYO(1,W,O(library.lib_Version     )), { 1 } } },
  106.     { { I_CPYO(1,W,O(library.lib_Revision    )), { 0 } } },
  107.     { { I_CPYO(1,L,O(library.lib_IdString    )), { (IPTR)&version[6] } } },
  108.     I_END ()
  109. };
  110.  
  111. #undef O
  112.  
  113. __AROS_LH2(struct dummybase *, init,
  114.  __AROS_LHA(struct dummybase *, dummybase, D0),
  115.  __AROS_LHA(BPTR,               segList,   A0),
  116.        struct ExecBase *, SysBase, 0, dummy)
  117. {
  118.     __AROS_FUNC_INIT
  119.     /* This function is single-threaded by exec by calling Forbid. */
  120.  
  121.     /* Store arguments */
  122.     dummybase->sysbase=SysBase;
  123.     dummybase->seglist=segList;
  124.  
  125.     /* You would return NULL here if the init failed. */
  126.     return dummybase;
  127.     __AROS_FUNC_EXIT
  128. }
  129.  
  130. /* Use This from now on */
  131. #ifdef SysBase
  132. #undef SysBase
  133. #endif
  134. #define SysBase dummybase->sysbase
  135.  
  136. __AROS_LH1(struct dummybase *, open,
  137.  __AROS_LHA(ULONG, version, D0),
  138.        struct dummybase *, dummybase, 1, dummy)
  139. {
  140.     __AROS_FUNC_INIT
  141.     /*
  142.     This function is single-threaded by exec by calling Forbid.
  143.     If you break the Forbid() another task may enter this function
  144.     at the same time. Take care.
  145.     */
  146.  
  147.     /* Keep compiler happy */
  148.     version=0;
  149.  
  150.     /* I have one more opener. */
  151.     dummybase->library.lib_OpenCnt++;
  152.     dummybase->library.lib_Flags&=~LIBF_DELEXP;
  153.  
  154.     /* You would return NULL if the open failed. */
  155.     return dummybase;
  156.     __AROS_FUNC_EXIT
  157. }
  158.  
  159. __AROS_LH0(BPTR, close, struct dummybase *, dummybase, 2, dummy)
  160. {
  161.     __AROS_FUNC_INIT
  162.     /*
  163.     This function is single-threaded by exec by calling Forbid.
  164.     If you break the Forbid() another task may enter this function
  165.     at the same time. Take care.
  166.     */
  167.  
  168.     /* I have one fewer opener. */
  169.     if(!--dummybase->library.lib_OpenCnt)
  170.     {
  171.     /* Delayed expunge pending? */
  172.     if(dummybase->library.lib_Flags&LIBF_DELEXP)
  173.         /* Then expunge the library */
  174.         return expunge();
  175.     }
  176.     return 0;
  177.     __AROS_FUNC_EXIT
  178. }
  179.  
  180. __AROS_LH0(BPTR, expunge, struct dummybase *, dummybase, 3, dummy)
  181. {
  182.     __AROS_FUNC_INIT
  183.  
  184.     BPTR ret;
  185.     /*
  186.     This function is single-threaded by exec by calling Forbid.
  187.     Never break the Forbid() or strange things might happen.
  188.     */
  189.  
  190.     /* Test for openers. */
  191.     if(dummybase->library.lib_OpenCnt)
  192.     {
  193.     /* Set the delayed expunge flag and return. */
  194.     dummybase->library.lib_Flags|=LIBF_DELEXP;
  195.     return 0;
  196.     }
  197.  
  198.     /* Get rid of the library. Remove it from the list. */
  199.     Remove(&dummybase->library.lib_Node);
  200.  
  201.     /* Get returncode here - FreeMem() will destroy the field. */
  202.     ret=dummybase->seglist;
  203.  
  204.     /* Free the memory. */
  205.     FreeMem((char *)dummybase-dummybase->library.lib_NegSize,
  206.         dummybase->library.lib_NegSize+dummybase->library.lib_PosSize);
  207.  
  208.     return ret;
  209.     __AROS_FUNC_EXIT
  210. }
  211. __AROS_LH0I(int, null, struct dummybase *, dummybase, 4, dummy)
  212. {
  213.     __AROS_FUNC_INIT
  214.     return 0;
  215.     __AROS_FUNC_EXIT
  216. }
  217.  
  218. __AROS_LH2I(ULONG, add,
  219.     __AROS_LHA(ULONG,a,D0),
  220.     __AROS_LHA(ULONG,b,D1),
  221.     struct dummybase *,dummybase,5,dummy)
  222. {
  223.     __AROS_FUNC_INIT
  224.     return a+b;
  225.     __AROS_FUNC_EXIT
  226. }
  227.  
  228. __AROS_LH2I(ULONG, asl,
  229.     __AROS_LHA(ULONG,a,D0),
  230.     __AROS_LHA(ULONG,b,D1),
  231.     struct dummybase *,dummybase,6,dummy)
  232. {
  233.     __AROS_FUNC_INIT
  234.     return a<<b;
  235.     __AROS_FUNC_EXIT
  236. }
  237.  
  238. const char end=0;
  239.